<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加记事</title>
    {% include "./header.html" %}
</head>

<body>
    <form role="form" method="post">
        <div class="box-body">
            <div class="form-group">
                <label for="name">记事标题</label>
                <input class="form-control" id="title" name="title" placeholder="请输入记事标题">
            </div>
            <div class="form-group">
                <label for="name">记事日期</label>
                <div class="input-group date">
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </div>
                    <input type="text" class="form-control pull-right" id="datepicker">
                </div>
            </div>
            <div class="form-group">
                <label for="remark">所属分类</label>
                <div class="form-group">
                    <select class="form-control" id="category_name">
                            {% for item in category %}
                            <option>{{item.name}}</option>
                            {% endfor %}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="remark">记事详情</label>
                <form>
                    <textarea class="textarea" id="content" name="content" placeholder="Place some text here" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                </form>
            </div>
        </div>
        <div class="box-footer">
            <button type="button" class="btn btn-primary button">确认提交</button>
        </div>
    </form>
    {% include "./footer.html" %}
</body>
<script>
    $(function () {
        //bootstrap WYSIHTML5 - text editor
        $('.textarea').wysihtml5()
        $('#datepicker').datepicker({
            autoclose: true,
            language:"zh-CN",
            format: 'yyyy-mm-dd'
        })
        $(".button").click(function () {
            var title = $("#title").val();
            var content = $("#content").val();
            var category_name = $("#category_name").val();
            var times= $("#datepicker").val();
            $.ajax({
                type: 'post',
                url: 'http://127.0.0.1:8360/thing/save',
                data: { "title": title, "content": content, "category_name": category_name,"times":times },
                success: function (data) {
                    if (data.succ) {
                        alert("添加成功");
                        window.location.href = "http://127.0.0.1:8360/thing/index"
                    } else {
                        alert("添加失败");
                    }
                }
            });

        });
    })

</script>

</html>